import os
from flask import Flask,render_template,url_for,request,make_response,abort,redirect

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'
@app.route('/upload')
def upload():
    return render_template('upload.html')
@app.route('/upload_submit',methods=['post'])
def upload_submit():
    file = request.files['file']
    print(file)
    os.path.dirname(__file__)
    save_path =os.path.join(os.path.dirname(__file__),'static/userfile/',file.filename)
    print(save_path)
    file.save(save_path)
    return '保存完成'

@app.route('/login',methods=['GET','POST'])
def login():
    print(request.method)
    if request.method=='GET':
        return render_template('login.html')
    elif request.method =='POST':
        form =request.form
        username =form['username']
        password =form['password']
        print(username,password)
        pass
        response = make_response(render_template('index.html'))
        response.set_cookie('username',username)
        return response

@app.route('admin')
def admin():
    abort(401)

@app.errorhandler(404)
def error404(error):
    return redirect(url_for('hello_world'),code=302)

if __name__=='__main__':
    app.run()
